package com.jms.tomcat.stream;

import javax.servlet.ServletOutputStream;
import javax.servlet.WriteListener;
import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;

public class BfOutputStream extends ServletOutputStream {

    private final ByteArrayOutputStream byteArrayOutputStream;


    public BfOutputStream() {
        byteArrayOutputStream = new ByteArrayOutputStream();
    }

    @Override
    public boolean isReady() {
        return false;
    }

    @Override
    public void setWriteListener(WriteListener writeListener) {

    }

    @Override
    public void write(int b) {
        byteArrayOutputStream.write(b);
    }

    public String getString() throws UnsupportedEncodingException {
        return byteArrayOutputStream.toString("UTF-8");
    }
}
